<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="text" id="input">
    <span id="sp"></span>

    <button id="btn">改变值</button>

    <script>

        const input = document.getElementById('input')
        const span = document.getElementById('sp')

        const obj = {}

        // 使用proxy代理
        const proxyObj = new Proxy(obj, {
            set(target, prop, val) {
                input.value = val
                span.innerText = val
            }
        })


        btn.onclick = function () {
            proxyObj.text = '123'
        }

        // 箭头输入事件
        input.addEventListener('input', function () {
            proxyObj.text = input.value
        })




    </script>
</body>

</html>